package com.bw.service.technology.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bw.entity.technology.PiOrderPic;
import com.bw.mapper.technology.PiOrderPicMapper;
import com.bw.service.technology.IPiOrderPicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.FileInputStream;
import java.io.InputStream;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhouxin
 * @since 2020-06-22
 */
@Service
public class PiOrderPicServiceImpl extends ServiceImpl<PiOrderPicMapper, PiOrderPic> implements IPiOrderPicService {

    private String filename="D:\\fileDB\\";

    @Autowired
    private PiOrderPicMapper orderPicMapper;

    @Override
    public InputStream getPic(Long itemId, String code) {

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("itemId",itemId);
        queryWrapper.eq("code",code);
        PiOrderPic piOrderPic = orderPicMapper.selectOne(queryWrapper);
        if (piOrderPic!=null){
            try {
                FileInputStream fileInputStream = new FileInputStream(filename + piOrderPic.getFilePath());
                return fileInputStream;
            }catch (Exception e){
                e.toString();
            }
        }
        return null;
    }
}
